// @ts-ignore
import { parse as parse_ } from '../../output/Parse/index'
// @ts-ignore
import { showProc, proc2c } from '../../output/Show/index'
// @ts-ignore
import { optimize, normalize } from '../../output/Transform/index'
// @ts-ignore
import { encodeProc } from '../../output/CodeGen/index'

declare const Proc: unique symbol
export type Proc = { [Proc]?: never }

export function parse(s: string): Proc | string {
  try {
    return parse_(s)()
  } catch (e) {
    if (e instanceof Error) return e.message
    return 'Unknown error'
  }
}

export function procToString(p: Proc): string {
  return showProc(p)(0)
}

export function procToC(p: Proc): string {
  return proc2c(p)(0)
}

declare const encodeProc: (p: Proc) => Uint8Array
export { encodeProc as procToWasm }

declare const optimize: (p: Proc) => Proc
export { optimize }

declare const normalize: (p: Proc) => Proc
export { normalize }
